#include <QtCore/QCoreApplication>
#include <QLibrary>
#include "Rules/IRule/IRule.h"
#include "Channels/IChannel/ichannel.h"

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    QLibrary channelLib("F:/KP/QtScada/Debug/Channels/TcpClientChannel");
    if (channelLib.load())
    {

        typedef IChannel* (*CreateChannelFunc)();
        typedef void (*ReleaseChannelFunc)(IChannel* pChannel);


        CreateChannelFunc createChannel =
                (CreateChannelFunc) channelLib.resolve("CreateChannel");
        ReleaseChannelFunc releaseChannel =
                (ReleaseChannelFunc) channelLib.resolve("ReleaseChannel");

        if (createChannel && releaseChannel)
        {

            IChannel* pChannel = createChannel();
            if (pChannel)
            {
                pChannel->HelloWord();
                releaseChannel(pChannel);
            }
        }
        channelLib.unload();
    }

    QLibrary ruleLib("F:/KP/QtScada/Debug/Rules/RULE_IEC101");
    if (ruleLib.load())
    {

        typedef IRule* (*CreateRuleFunc)();
        typedef void (*ReleaseRuleFunc)(IRule* pRule);


        CreateRuleFunc createRule =
                (CreateRuleFunc) ruleLib.resolve("CreateRule");
        ReleaseRuleFunc releaseRule =
                (ReleaseRuleFunc) ruleLib.resolve("ReleaseRule");

        if (createRule && releaseRule)
        {

            IRule* pRule = createRule();
            if (pRule)
            {
                pRule->Eat();
                pRule->Run();
                pRule->Sleep();
                pRule->HelloWord();
                releaseRule(pRule);
            }
        }

        ruleLib.unload();
    }

    return a.exec();
}
